# notepad $PROFILE
# D:\liujin\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
# oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\atomic.omp.json" | Invoke-Expression
oh-my-posh init pwsh --config "D:\liujin\Documents\PowerShell\my_theme.omp.json" | Invoke-Expression
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo # 设置 Ctrl+z 为撤销
Set-PSReadLineKeyHandler -Key "Ctrl+b" -Function Complete # 设置 Ctrl+b 补全
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete  # 设置 Tab 键为菜单补全
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward # 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward # 设置向下键为前向搜索历史纪录
Set-PSReadLineOption -PredictionSource History  # 设置预测文本来源为历史记录
Set-PSReadLineOption -PredictionViewStyle ListView

# 几个常用的命令
New-Alias open invoke-item #用默认程序打开文件
New-Alias which get-command #查找命令
# 查看目录 ls & ll
function ListDirectory {
    (Get-ChildItem).Name
    Write-Host("")
}
Set-Alias -Name ls -Value ListDirectory
New-Alias -Name ll -Value Get-ChildItem
New-Alias -Name la -Value Get-ChildItem
New-Alias -Name touch -Value  New-Item
New-Alias -Name grep -Value Select-String

# wt 配置文件
$wtfile="C:/Users/liujin/AppData/Local/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState/settings.json"

# 更改环境变量 PATH
# $env:PATH = "D:\path;" + $env:PATH

# 重新加载环境变量 Path, 使得对环境变量的更改立即生效
function resetEnv {
    Set-Item `
        -Path (('Env:', $args[0]) -join '') `
        -Value ((
            [System.Environment]::GetEnvironmentVariable($args[0], "Machine"),
            [System.Environment]::GetEnvironmentVariable($args[0], "User")
        ) -match '.' -join ';')
}
resetEnv Path

# 查看文件大小
Function du{
	[cmdletbinding()]
    Param($path='./' )

	dir -Path $path -Force |
	ForEach-Object -Process {
		if ($_.PSIsContainer -eq $true)
		{
			$length = 0
			dir -Path $_.fullname -Recurse -Force | ForEach-Object{
				$length += $_.Length
			}

			$common = "`e[38;5;3m$($_.name)`e[0m:  "
			if ($length -gt 1GB) {
				$l = $length/1GB
				$common + "{0:n1} GB" -f $l
				# $_.name + "文件夹的大小为:  {0:n1} GB" -f $l
			} elseif ($length -gt 1MB) {
				$l = $length/1MB
				$common + "{0:n1} MB" -f $l
				# $_.name + "文件夹的大小为:  {0:n1} MB" -f $l
			} else {
				$l = $length/1KB
				$common + "{0:n1} KB" -f $l
			}
		} else {
			$length = $_.Length
			$common = "`e[38;5;33m$($_.name)`e[0m:  "

			if ($length -gt 1GB) {
				$l = $length/1GB
				$common + "{0:n1} GB" -f $l
			} elseif ($length -gt 1MB) {
				$l = $length/1MB
				$common + "{0:n1} MB" -f $l
			} else {
				$l = $length/1KB
				$common + "{0:n1} KB" -f $l
			}
		}
	}
}

# 代理设置
# $env:HTTP_PROXY="socks5://127.0.0.1:50052"
# $env:HTTPS_PROXY="socks5://127.0.0.1:50052"